<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="/js/jquery-3.3.1.min.js"></script>
</head>
<body>
    <form id="form">
        <span>username:</span>
        <input type="text" name="username"><br>
        <span>password:</span>
        <input type="password" name="password"><br>
        rememberMe <input id="rememberMe" type="checkbox" name="rememberMe" value="false">
        <button id="login" type="button">登录</button>
    </form>
    <script>
        $.fn.serializeObject = function() {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function() {
                if (o[this.name]) {
                    if (!o[this.name].push) {
                        o[this.name] = [ o[this.name] ];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        }

        $("#rememberMe").click(function () {
            this.value = this.checked;
        })

        $("#login").on("click", function () {
            var json = $("#form").serializeObject();
            // json.rememberMe = $("#rememberMe").val();
            console.log(json);
            $.ajax({
                type:"post",
                url:"/login",
                contentType: "application/json",
                data:JSON.stringify(json),
                success:function(result){
                    if (result.isSuccess) {
                        alert(result.message);
                        setTimeout(function(){
                            location.href = "/index.html"
                        }, 500);
                    } else {
                        alert(result.message);
                    }
                }
            });
        })
    </script>
</body>
</html>